<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- 新 Bootstrap 核心 CSS 文件 -->
<title>后台管理-首页</title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<%-- <link rel="stylesheet"
	href="<c:url value='/share/bootstrap.min.css'></c:url>"> --%>
<link rel="stylesheet"
	href="<c:url value='/share/AllStyle.css'></c:url>">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="<c:url value='/js/jquery.min.js'></c:url>"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="<c:url value='/js/bootstrap.min.js'></c:url>"></script>
<script src="<c:url value='/js/all.js'></c:url>"></script>
<%-- <script src="<c:url value='/js/rqfCommon/sockjs-0.3.min.js'></c:url>"></script> --%>
<script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script src="<c:url value='/js/rqfCommon/stomp.js'></c:url>"></script>
<script src="<c:url value='/js/serverCommonJs.js'></c:url>"></script>
<script src="<c:url value='/js/rqfCommon/rqfCommon.js'></c:url>"></script>

<link rel="stylesheet" href='<c:url value="/share/pintuer.css"></c:url>'>
<link rel="stylesheet" href='<c:url value="/share/admin.css"></c:url>'>

<script src="<c:url value='/js/jquery.min.js'></c:url>"></script>
<script
	src='<c:url value="/js/rqfui/rqfui.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script type="text/javascript"
	src='<c:url value="/js/pintuer.js"></c:url>'></script>
<script type="text/javascript"
	src='<c:url value="/js/admin.js"></c:url>'></script>
<style>
	.wh_Home_news{
		float: left;
		padding-bottom: 10px;
		position: absolute;
		right:140px;
		display : none;
	}
	.header-tool-news .header-tc-content {
	    width: 302px;
	    padding: 0 26px;
	    line-height: 34px;
	    right: -69px;
	    text-align: center;
	}
	.header-tc-content {
		display: none; 
	    position: absolute;
	    border: 1px solid #ccc;
		width: 310px;
	    left: -153px;
	    top: 37px;
	    background-color: #fff;
	    text-align: left;
	    /* display: none; */
	    z-index: 2;
	    color: #4b4b4b;
	    font-size: 12px;
	    height: auto!important;
	    min-height: 32px;
	    height: 32px;
	    box-shadow: 0 2px 5px #d5d5d5;
	}
	
	.header-tool-news .header-tc-content .header-tc-ct-bg {
	    right: 76px;
	}
	.header-tc-ct-bg {
	    position: absolute;
	    top: -15px;
	    left: 50%;
	    width: 0;
	    height: 0;
	    border: 7px solid #ccc;
	    border-color: transparent transparent #ccc;
	    z-index: 5;
	}
	
	.header-tc-ct-bg:before {
	    content: "";
	    position: absolute;
	    top: -7px;
	    right: -8px;
	    width: 0;
	    height: 0;
	    border: 8px solid #fff;
	    border-color: transparent transparent #fff;
	    z-index: 3;
	}
	.news-title {
    	line-height: 42px;
   	 	overflow: hidden;
    	border-bottom: 1px solid #2459aa;
    	margin: 0 18px;
	}
	.news-list {
	    margin: 0;
	    padding: 0;
	    max-height: 332px;
	    overflow-y: auto;
	    margin: 0 18px;
	    position: relative;
	}
	.news-bottom {
	    line-height: 42px;
	    text-align: center;
	    border-top: 1px solid #e0e6f1;
	    background: #f6f6f6;
	    color: rgb(180, 180, 180);
	}
	.news-title .news-title-ctx {
	    color: #2459aa;
	    font-size: 14px;
	    float: left;
	}
	.news-bottom .news-more {
	    color: #b4b4b4;
	    font-size: 14px;
	    cursor: pointer;
	    text-decoration: none;
	}
	.news-item{
		line-height: 60px;
		border-bottom: 1px solid #e0e6f1;
	}
	.news-item:last-child {
	    border-bottom: none;
	}
	.news-ctx-link{
	  color: rgb(124, 124, 125);
	  font-size: 14px;
	  overflow: hidden;
	  width: 225px;
	  padding: 0 10px;
	  text-overflow: ellipsis;
	  white-space: nowrap;
	  display: block;
	  float: left;
	}
	.news-ctx{
		position: relative;
	    overflow: hidden;
	}
</style>	
</head>
<body>
	<div class="lefter">
		<div class="logo">
			<a href="javascript:;" target="_blank">后台管理系统</a>
		</div>
	</div>
	<div class="righter nav-navicon" id="admin-nav">
		<div class="mainer">
			<div class="admin-navbar">
				<span class="float-right"> 
				
				<div class="wh_Home_news">
							<div class="header-tc-content">
			                    <span class="header-tc-ct-bg"></span>
			                    <div class="news-header">
			                    	<div class="news-title clr">
			                    		<span class="news-title-ctx">消息</span>
			                    	</div>
			                    	<ul class="news-list" id="news-list">
			                    	</ul>
			                    	<div class="news-bottom clearfix">
			                    		<a class="news-more" href="<c:url value="/msg/1" />" target="_blank">查看所有消息>></a>
			                    	</div>
			                    </div>
			                </div>
							<a id="remindId" href="javascript:;"
								style="display: block; width: 18px;height: 18px;top: -8px;text-align: center; left: 20px; background: #e93a44; position: absolute; margin: 0; border: 0; border-radius: 100%; line-height: 18px; color: #fff; padding: 0px 4px; font-size: 12px;"></a>
							<img src="<c:url value='/share/images/black1.png'></c:url>"
								id="touxiang_lingdang"
								style="width: 18.85px; height: 24px; margin-top: 0px; cursor: pointer;margin-right:25px">
							<span class="vertical" style="margin: 0 20px; margin-top: 10px;"></span>
						</div>
					<a class="button button-little bg-main" href="<c:url value='/'></c:url>" target="_blank">前台首页</a>
					<a class="button button-little bg-yellow" href="<c:url value='/admin/logout'></c:url>">注销</a>
					<a class="button button-little bg-yellow"  href="javascript:jumpUrl();">修改密码</a>
				</span>
				<ul class="nav nav-inline admin-nav">
					<c:forEach items="${menuList}" var="m" varStatus="status">
						<c:if test="${status.index == 0}">
							<li class="menu1 active"><a href="javascript:;">
									${m.name}</a>
						</c:if>
						<c:if test="${status.index > 0}">
							<li class="menu1"><a href="javascript:;"> ${m.name}</a>
						</c:if>
						<ul class="menu2">
							<c:if test="${not empty m.menu_sub}">
								<c:forEach items="${m.menu_sub}" var="sub_m" varStatus="st">
									<c:if test="${st.index == 0}">
										<li class="active"><a href="javascript:;"
											data='${sub_m.function}'>${sub_m.name}</a></li>
									</c:if>
									<c:if test="${st.index > 0}">
										<li><a href="javascript:;" data='${sub_m.function}'>${sub_m.name}</a></li>
									</c:if>

								</c:forEach>
							</c:if>
						</ul>
						</li>
					</c:forEach>
				</ul>
			</div>
			<div class="admin-bread">
				<span>您好，${nickname}，欢迎您的光临。</span>
				<ul class="bread">
					<li><a href="javascript:;" class="icon-home" id='m1'> 开始</a></li>
					<li id='m2'>后台首页</li>
				</ul>
			</div>
		</div>
	</div>
	<div class="admin">
		<iframe width="100%" height="100%" frameborder="0" id="main_frame"
			scrolling="yes" src="<c:url value='/mngindex/home'></c:url>">
		</iframe>
	</div>
	<div id="alertSound" style="display: none"></div>

</body>
<script type="text/javascript">
$(function(){
	

	
	
	set_location();
	$('.menu1').click(function(){
		$('.menu1').removeClass("active");
		$(this).addClass("active");
		set_location();
	});

	$('.menu2 li').click(function(){
		$(this).parent().children('li').removeClass("active");
		$(this).addClass("active");
	});
});




var uuid = '${uuid}';
var tabId = '${tabId}';
var rootPath = '${rootPath}';
if(!tabId){
	tabId = '1';
}

var showMsg = false;

if (uuid && showMsg) {
	var socket = new SockJS("/eduPlatform/ws");
	var stompClient = Stomp.over(socket);
	
	// Callback function to be called when stomp client is connected to server
	var connectCallback = function() {
		stompClient.subscribe('/topic/msgfetch/' + uuid, getUnReadMsg);
	};
	// Callback function to be called when stomp client could not connect to server
	var errorCallback = function(error) {
		//alert(error.headers.message);
		alert(error);
	};
	// Connect to server via websocket
	stompClient.connect("guest", "guest", connectCallback, errorCallback);
	
	//getUnReadMsg();
}

$(function() {
	$(".home_header-nav li").click(function() {
		$(".home_header-nav li a").removeClass("home_header_1_ClickA");
		//$(this).children().addClass("home_header_1_ClickA");
	});
	//消息信息
 	$(".wh_Home_news").hover(function(){
		$(".header-tc-content").show();
	},function(){
		$(".header-tc-content").hide();
	}); 
});

/* function naviClick() {
	var url = '<c:url value="/msg/1" />';
	//$('#li'+tabId).children().addClass("home_header_1_ClickA");
	//var height = $(this).outerHeight() - 93 + "px";
	$('#main_frame').css('height', height).css('width', '100%').attr(
			'src', url); 
} */

//有新的推送，获取未读消息条数并显示
function getUnReadMsg() {
	var htmlStr = '<audio src="'+rootPath+'/share/voice/remind.m4a" autoplay="autoplay"></audio>';
	$('#alertSound').html(htmlStr);
	init_count();
}

//消息查看
function checkMsg(){
	
}

$("#news-list li").click(function(){
	var DataUrl = $(this).children().children("a").data('url');
	$(".clearfix li a").removeClass("home_header_1_ClickA");
	$("#contentPan").attr("src",DataUrl);
});

var NewsListHtml;
var ContentHtml = "";
var MsgTitle = "";
var MsgDetailsHtml = "";
$("#news-list").bind("click","li>div>a",function(){
	var id = $(this).data('id');
	//init_count();
	$(".modal-body").html(MsgDetailsHtml);
	$(".modal-body-details").html(ContentHtml);
	$("#myModalLabel").html(MsgTitle);
	init_msg(1);
	if($("#contentPan").attr("src") == "/eduPlatform/msg/1"){
		$("#contentPan").attr("src","/eduPlatform/msg/1");
	}
})
init_msg();
//获取消息推送信息
function init_msg(type){
	var url = "<c:url value='/msg/list'></c:url>";
	$.ajax({
		url: url,
		type: 'POST',
		dataType: 'html',
		data:{
			"pageSize": 4,
			"uuid": uuid,
			"notRead": true
		},
		success:function(data){
			var obj = gridDataFormat(data);
			console.log(obj);
			var html = "";
			var AlertHtml = "";
			ContentHtml = "";
			MsgTitle = "";
			MsgDetailsHtml = "";
			if(obj.count == 0){
				html += '<li class="news-item clr">'+
			            	'<div class="news-ctx clr" style="text-align: center;">'+
		        				'目前没有新消息'+
		        			'</div>'+
		        		'</li>';
			}
			for(var i=0;i<obj.count;i++){
				ContentHtml = obj.data[i].msgCon == null?"无":obj.data[i].msgCon;
				MsgTitle = obj.data[i].msgName == null?"无":obj.data[i].msgName;
				pushTime = obj.data[i].pushTime == null?"无":obj.data[i].pushTime;
				creater = obj.data[i].creater == null?"无":obj.data[i].creater;
				createTime = obj.data[i].createTime == null?"无":obj.data[i].createTime;
				createTime = createTime.substring(0,10) +"&nbsp;"+ createTime.substring(11,16);
				pushReason = obj.data[i].pushReason == null?"无":obj.data[i].pushReason;
			    MsgDetailsHtml = '<div style="width: 195px; float: left;">'+
				       			 	'接收人：'+ MsgTitle +''+
					      		 '</div>'+
					      		 '<div>'+
					      		 	 '推送时间：'+ pushTime +''+
					      		 '</div>'+
					      		 '<div style="width: 195px; float: left;">'+
					      			 '编制人：'+ creater +''+
					      		 '</div>'+
					      		 '<div>'+
					      			 '编制时间：'+ createTime +''+
					      		 '</div>'+
					      		 '<div>'+
					      			 '推送原因： '+ pushReason +''+
					      		 '</div>';
				AlertHtml = obj.data[i].type == "自定义"?'data-toggle="modal" data-target="#myModal" href="javascript:;"':'target="_blank" href="<c:url value="/surveyAnalyze/answerMv/'+ obj.data[i].relatedId +'"></c:url>"';
				html += '<li class="news-item clr" onclick="state_change('+ obj.data[i].id +')">'+
		            		'<div class="news-ctx clr">'+
		        				'<a class="news-ctx-link  blank_to" '+ AlertHtml +' data-id="'+ obj.data[i].id +'" data-url="/eduPlatform/msg/'+ obj.data[i].id +'" data-state="'+ obj.data[i].state +'" title="'+ obj.data[i].type +'—'+ obj.data[i].msgName +'">'+ obj.data[i].type +'—'+ obj.data[i].msgName +'</a>'+
		        				'<div class="news-type news-app11" style="width: 8px;height: 8px;border-radius: 50%;background: #eb3f3f;float: left;margin-top: 25px;margin-left: 15px;"></div>'+
		        			'</div>'+
		        		'</li>';
			}
			
			NewsListHtml = html;
			$("#news-list").html(html);
			if(type != 1){
				$(".modal-body").html(MsgDetailsHtml);
				$(".modal-body-details").html(ContentHtml);
				$("#myModalLabel").html(MsgTitle);
			}
		},
		error:function(){
			//console.log();
		}
	});
}

//改变状态
function state_change(id){
	var url = "<c:url value='/msg/read'></c:url>";
	$.ajax({
		url: url,
		type: 'POST',
		dataType: 'html',
		data:{
			"ids":id
		},
		success:function(data){
			if(data < 1){
				//alert("阅读失败");
				$("#remindId").hide();
				location.reload();
			}
		},
		error:function(){
			//console.log();
		}
	});
}

init_count();
//获取未读数
function init_count(){
	var url = "<c:url value='/msg/count'></c:url>";
	$.ajax({
		url: url,
		type: 'POST',
		dataType: 'JSON',
		data:{
			"uuid": uuid,
			"notRead": true
		},
		success:function(data){
			if(data < 1){
				$("#remindId").hide();
				data = "";
				
			}else if(data > 9){
				$("#remindId").show();
				data = "...";
			}

			$("#remindId").html(data);
		},
		error:function(){
			//console.log();
		}
	});
}


/**
 * 改变iframe和面包屑功能
 */
function set_location(){
	$('#m1').html($("li[class='menu1 active'] > a").html());
	$('#m1').attr('class',$("li[class='menu1 active'] > a").attr('class'));
	$('#m2').html($("li[class='menu1 active'] .active a").html());
	url = $("li[class='menu1 active'] .active a").attr('data');
	$('#main_frame').attr('src',url);
}

function jumpUrl(){
	var src="<c:url value='/admin/update'></c:url>";
	$('#main_frame').attr('src',src);
}
</script>
</html>
